package cn.elead.chaos.remote.web.system.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.elead.chaos.core.enums.BusinessType;
import cn.elead.chaos.excel.ExcelUtil;
import cn.elead.chaos.framework.monitor.operlog.Log;
import cn.elead.chaos.mybatils.web.controller.BaseController;
import cn.elead.chaos.mybatils.web.page.TableDataInfo;
import cn.elead.chaos.remote.web.system.service.IRemotePostService;
import cn.hutool.core.util.StrUtil;
import cn.elead.chaos.remote.web.system.domain.SysPost;

/**
 * 岗位信息Controller
 * 
 * @author luopeng
 * @date 2020-02-26 14:54:24
 */
@RestController
@RequestMapping("/remote/system/post")
public class RemotePostController extends BaseController
{
    @Autowired
    private IRemotePostService postService;

    /**
     * 查询岗位信息列表
     */
    @GetMapping("/page")
    @RequiresPermissions("system:post:list")
    public TableDataInfo<SysPost> page(SysPost sysPost) {
        return postService.page(sysPost);
    }

    /**
     * 导出岗位信息列表
     */
    @GetMapping("/export")
    @RequiresPermissions("system:post:export")
    @Log(title = "岗位信息", businessType = BusinessType.EXPORT)
    public String export(SysPost sysPost) {
        List<SysPost> list = postService.list(sysPost);
        ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
        return util.exportExcel(list, "post");
    }

    /**
     * 获取岗位信息详细信息
     */
    @GetMapping(value = "/{postId}") 
    @RequiresPermissions("system:post:list")
    public SysPost getInfo(@PathVariable("postId") Long postId) {
       	return postService.getInfo(postId);
    }

    /**
     * 新增岗位信息
     */
    @PostMapping
    @RequiresPermissions("system:post:add")
    @Log(title = "岗位信息", businessType = BusinessType.INSERT)
    public int add(@RequestBody SysPost sysPost) {
    	return postService.add(sysPost);
    }

    /**
     * 修改岗位信息
     */
    @PutMapping
    @RequiresPermissions("system:post:edit")
    @Log(title = "岗位信息", businessType = BusinessType.UPDATE)
    public int edit(@RequestBody SysPost sysPost) {
        return postService.edit(sysPost);
    }

    /**
     * 删除岗位信息
     */
	@DeleteMapping("/{postId}")
    @RequiresPermissions("system:post:remove")
    @Log(title = "岗位信息", businessType = BusinessType.DELETE)
    public int remove(@PathVariable Long[] postIds){
		String ids = StringUtils.join(postIds, StrUtil.COMMA);
        return postService.remove(ids);
    }
	
	
	/**
	 * 获取岗位选择框列表
	 */
	@GetMapping("/optionselect")
	public List<SysPost> optionselect() {
		return postService.optionselect();
	}
}
